package com.yisoo.ubag.iot.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yisoo.ubag.iot.entity.StatusEntity;
import com.yisoo.ubag.iot.service.StatusService;
import com.yisoo.common.utils.PageUtils;
import com.yisoo.common.utils.R;



/**
 * 
 *
 * @author mmciel
 * @email 761998179@qq.com
 * @date 2021-03-07 13:09:16
 */
@RestController
@RequestMapping("iot/status")
public class StatusController {
    @Autowired
    private StatusService statusService;

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    /**
     * 列表
     */
    @RequestMapping("/get/by/name/{devname}")
    //@RequiresPermissions("iot:status:list")
    public R getByName(@PathVariable("devname")String devName){
        return statusService.getStatusByDevName(devName);
    }




    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("iot:status:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = statusService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{statusId}")
    //@RequiresPermissions("iot:status:info")
    public R info(@PathVariable("statusId") Integer statusId){
		StatusEntity status = statusService.getById(statusId);

        return R.ok().put("status", status);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("iot:status:save")
    public R save(@RequestBody StatusEntity status){
		statusService.save(status);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("iot:status:update")
    public R update(@RequestBody StatusEntity status){
		statusService.updateById(status);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("iot:status:delete")
    public R delete(@RequestBody Integer[] statusIds){
		statusService.removeByIds(Arrays.asList(statusIds));

        return R.ok();
    }

}
